package com.yitiao.data_algorithms.leetcode.editor.cn;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class InvertBinaryTree{
    // 2023-02-09 14:57:08
    public static void main(String[] args) {
        Solution solution = new InvertBinaryTree().new Solution();
    }
    
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public TreeNode invertTree(TreeNode root) {
        dfs(root);
        return root;
    }

    private void dfs(TreeNode root) {
        if (root==null)return;
        dfs(root.left);
        dfs(root.right);
        TreeNode node = root.left;
        root.left = root.right;
        root.right = node;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}